# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=aichat
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.29.0
pkgrel=1
pkgdesc="All-in-one AI CLI tool featuring Chat-REPL, Shell Assistant, RAG, AI tools & agents (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/sigoden/aichat'
msys2_references=(
  'archlinux: aichat'
)
license=('spdx:MIT OR Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('0b586419ce4e29e02eb165e0ab668e0661fac305840348467ab5f45e42551a5a')

prepare() {
  cd "${_realname}-${pkgver}"
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"
  cargo build --frozen --release --all-features
}

package() {
  cd "${_realname}-${pkgver}"
  install -vDm755 -t "${pkgdir}${MINGW_PREFIX}/bin" target/release/aichat
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}" README.md
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE-APACHE
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE-MIT

  install -vDm644 scripts/completions/aichat.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/aichat"
  install -vDm644 scripts/completions/aichat.fish "${pkgdir}${MINGW_PREFIX}/share/fish/completions/aichat.fish"
  install -vDm644 scripts/completions/aichat.nu "${pkgdir}${MINGW_PREFIX}/share/nu/completions/aichat.nu"
  install -vDm644 scripts/completions/aichat.ps1 "${pkgdir}${MINGW_PREFIX}/share/powershell/completions/aichat.ps1"
  install -vDm644 scripts/completions/aichat.zsh "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_aichat"

  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.bash
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.nu
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.zsh
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.fish
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.ps1
}
